
$(function () {
  var commonYear = (new Date()).getFullYear();
  $('[page-href]').click(function(){
      var src = $(this).attr('page-href');
      window.parent.changeMainPage(src);
  })
  layui.use(['form','laydate'], function(){
      var laydate = layui.laydate;
      //年选择器
      laydate.render({ 
          elem: '#year',
          type: 'year',
          value: (new Date()).getFullYear(),
          min: -366,
          max: 0,
          done: function (value,date) {
              commonYear = value;
              setModelMain(true)
          },
          // change: function(value, date){ //监听日期被切换
          //     commonYear = value;
          //     setModelMain()
          // }
      });
 setVideo({
  id:"#stBox",
  showPageNumber:true,
   datas:[
       {name:"(2020)浙01民终10926号1",url:""},
       {name:"(2020)浙01民终10926号2",url:""},
       {name:"(2020)浙01民终10926号3",url:""},
       {name:"(2020)浙01民终10926号4",url:""},
       {name:"(2020)浙01民终10926号5",url:""},
       {name:"(2020)浙01民终10926号6",url:""},
       {name:"(2020)浙01民终10926号7",url:""},
       {name:"(2020)浙01民终10926号8",url:""},
       {name:"(2020)浙01民终10926号9",url:""},
       {name:"(2020)浙01民终10926号10",url:""},
       {name:"(2020)浙01民终10926号11",url:""},
       {name:"(2020)浙01民终10926号12",url:""},
       {name:"(2020)浙01民终10926号13",url:""},
       {name:"(2020)浙01民终10926号14",url:""},
       {name:"(2020)浙01民终10926号15",url:""},
       {name:"(2020)浙01民终10926号16",url:""},
       {name:"(2020)浙01民终10926号17",url:""},
       {name:"(2020)浙01民终10926号18",url:""},
       {name:"(2020)浙01民终10926号19",url:""},
       {name:"(2020)浙01民终10926号20",url:""},
       {name:"(2020)浙01民终10926号21",url:""},
       {name:"(2020)浙01民终10926号22",url:""},
       {name:"(2020)浙01民终10926号23",url:""},
       {name:"(2020)浙01民终10926号24",url:""},
       {name:"(2020)浙01民终10926号25",url:""},
       {name:"(2020)浙01民终10926号26",url:""},
      ],
  searchColumn:[
      {name: "仲裁院", field: "tsflag", type: "select",dicData: [{ label:'正在处理',value:'0'},{ label:'已办结',value:'1'}]},
      {name: "仲裁员", field: "isbb17", type: "text"},
      {name: "案号", field: "isbb17", type: "text"},
      {name: "时间", field: "aae036",type:"datePicker",range:false,subtype: "date",format: 'yyyy年MM月dd日'},
      {name: "至", field: "abb119",type:"datePicker",range:false,subtype: "month",format: 'yyyy年MM月'}
   ],
 })
      function  setVideo(config, mainClass){
          var id=config.id
          var formHTML = '';
          var data_=config.datas||[]
          if(config.searchColumn && config.searchColumn.length>0){
              formHTML = `<div class="search_column"><form class="layui-form" action="" lay-filter="allUnitsForm">`
             $.each(config.searchColumn,function(i,item){
              if(item.type == 'select'){
                  var selectHTML = '';
                  $.each(item.dicData,function(i,item){
                      selectHTML += `<option value="${item.value}">${item.label}</option>`;
                  })
                  formHTML += `<div class="layui-inline">
                              <label class="layui-form-label">${item.name}</label>
                              <div class="layui-input-inline">
                                  <select name="${item.field}" lay-verify="">
                                      <option value="">请选择</option>
                                      ${selectHTML}
                                  </select>  
                              </div>
                          </div>`;
              }else if (item.type == 'datePicker'){
                  formHTML += `<div class="layui-inline">
                                  <label class="layui-form-label">${item.name}</label>
                                  <div class="layui-input-inline">
                                      <input type="text" class="layui-input" data-type="datePicker" data-index="${i}" id="${item.field}" />
                                  </div>
                              </div>`;
              }else if (item.type == 'dropdown'){
                  formHTML += `<div class="layui-inline">
                                  <label class="layui-form-label">${item.name}</label>
                                  <div class="layui-input-inline">
                                      <div class="layui-input"  data-type="dropdown" data-index="${i}" id="${item.field}" ><div class="text text_overflow">请选择</div><i class="layui-icon layui-icon-down layui-font-12"></i></div>
                                  </div>
                              </div>`;
              }else if(item.type == 'tree'){
                  formHTML += `<button class="layui-btn" id="demo1">
                  ${item.name}
                  <i class="layui-icon layui-icon-down layui-font-12"></i>
                </button>`
              }else{
                  formHTML += `<div class="layui-inline">
                              <label class="layui-form-label">${item.name}</label>
                              <div class="layui-input-inline">
                                  <input type="text" name="${item.field}" placeholder="请输入" autocomplete="off" class="layui-input" />
                              </div>
                          </div>`;
              }
             });
             formHTML += '<button lay-submit class="layui-btn layui-btn-normal" lay-filter="allUnitsForm">查询</button>   </form></div>'
          }
          $(id).before(formHTML)
          var ecm="main_box"
          layui.use(['jquery', 'laydate', 'layedit', 'form'], function () {
              //dropdown = layui.dropdown
              var form = layui.form, $ = layui.jquery,laydate = layui.laydate;
              form.render();
              form.render('select', 'allUnitsForm');
              $('.' + ecm).parent().find('[data-type="datePicker"]').each(function(i,ele){
                  var index= $(this).attr('data-index');
                  laydate.render({
                      elem: '#'+config.searchColumn[index].field,
                      type: config.searchColumn[index].subtype,
                      range: config.searchColumn[index].range||false,
                      format:  config.searchColumn[index].format,
                      done: function(value, date, endDate){
                          //aae036StartTime/aae036EndTime
                          // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                          // console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
                          var startTime = {
                              year: date.year||'',
                              month: date.month?moreThanTen(date.month):'',
                              date: date.date?moreThanTen(date.date):''
                          };
                          var endTime = {
                              year: endDate.year||'',
                              month: date.month?moreThanTen(endDate.month):'',
                              date: date.date?moreThanTen(endDate.date):''
                          };
                          data.where[config.searchColumn[index].field+'StartTime'] = startTime.year + startTime.month + startTime.date;
                          data.where[config.searchColumn[index].field+'EndTime'] = endTime.year + endTime.month + endTime.date;
                      }
                    });
              })
              $('.' + ecm).parent().find('[data-type="dropdown"]').each(function(i,ele){
                  var index= $(this).attr('data-index');
                  // dropdown.render({
                  //     elem: '#'+data.searchColumn[index].field,
                  //     data: data.searchColumn[index].dicData,
                  //     click: function(obj){
                  //         $(ele+' .text').text(obj.title)
                  //         data.where[data.searchColumn[index].field] = obj.id;
                  //     },
                  //   });
                  //   return;
                  renderDropdown({
                      elem: '#'+config.searchColumn[index].field,
                      data:config.searchColumn[index].dicData,
                      textclick: function(obj){
                          $(ele).find(' .text').text(obj.title)
                          data.where[config.searchColumn[index].field] = obj.id;
                      },
                      iconClick:function(){
                          
                      }
                    });
  
              })
              form.on('submit(allUnitsForm)', function(formData){
                  console.log(formData.field) //当前容器的全部表单字段，名值对形式：{name: value}
                  $.each(formData.field,function(k,val){
                      data.where[k] = val;
                  })
                  setData(0);
                  $(id+' .pagenation .page_num').eq(0).addClass('active').siblings().removeClass('active');
                  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                });
          })
          var pageHTML='<div class="page_last "></div>',pageSize= config.pageSize||10,
          pages = Math.ceil(data_.length/pageSize),pageIndex=0,nextIndex=0;
          data_ = data_.map((item,i)=>{
          item.pm = i+1;
          return item;
           })
      while(pages>0){
          pageIndex++;
          pageHTML += '<div class="'+(config.showPageNumber?'page_num':'')+'">'+(config.showPageNumber?pageIndex:'')+'</div>';
          pages--;
      };
      nextIndex=pageIndex
      pageHTML+=`<div class="page_next"></div>`
      $(id +" .pagenation").html(pageHTML)
      $(id+' .pagenation .page_num').eq(0).addClass('active');
      $(id+' .pagenation .page_num').click(function(){
          var index = $(this).index()-1;
          nextIndex=index
          setData(index);
          $(this).addClass('active').siblings().removeClass('active');
      });
      $(id+' .pagenation .page_next').click(function(){
          ++nextIndex
          setData(nextIndex);
          $(this).addClass('active').siblings().removeClass('active');
       });
       $(id+' .pagenation .page_last').click(function(){
          --nextIndex
          setData(nextIndex);
          $(this).addClass('active').siblings().removeClass('active');
       });
      setData(0)
      function setData(pageIndex){
          var dataHTML = '';
          var i = 0;
          var data = data_.slice(pageIndex*pageSize,(pageIndex+1)*pageSize);
           if(data.length>0){
              while(i<pageSize && i<data.length){
                  // console.log(dataHTML,"dataHTML")
                  $.each(data,function(i,item){
                      dataHTML+=` <div class="video_box">
                      <div class="video_main">
                      <video id="my_video" height="100%" width="100%" src=""></video>
                      </div>
                      <div class="video_text">${item.name}</div>
                    </div>`
                  })
                  // dataHTML += '<div class="item text_overflow pm_'+(data[i].pm)+'"><div class="pm_box"><span>TOP '+(moreThanTen(data[i].pm||1))+'</span></div>'+(data[i].gz_value||0)+'</div>';
                  i++;
              };
            
              $(id+' .datalist').html(dataHTML);
           }
         
      }
      }
  });
 







 
 


 




 

 
 

 

  






 
})